package com.base.taskreports;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.base.taskreports.reports.entiyt.lj.TblDiscountTransEnyity;
import com.base.taskreports.reports.entiyt.master.TIndicatorsEntity;
import com.base.taskreports.reports.service.LjTblDiscountTransService;
import com.base.taskreports.task.service.LjService;
import com.base.taskreports.task.service.PqdService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.base.taskreports.common.utlis.ExcelUtils;
import com.base.taskreports.common.utlis.FileUtils;
import com.base.taskreports.demoExel.entity.Indicator;
import com.base.taskreports.reports.service.ExcelBeanService;
import com.base.taskreports.reports.service.TblDiscountTransService;

@RunWith(SpringRunner.class)
@SpringBootTest()
public class WriterExcel {
	@Autowired
	private LjService ljService;

	@Autowired
	private PqdService pqdService;

	@Autowired
	private ExcelBeanService excelBeanService ;

	@Autowired
	private LjTblDiscountTransService ljTblDiscountTransService ;

	@Test
	public void test001() throws ParseException {

		String strDate = "2021-10-12" ;


		//List<List<Object>> list = excelBeanService.getExcelList(strDate,"LJ_M007") ;
		//ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M007.getIndex(), stratRow, list);

		//List<List<Object>> list = excelBeanService.getExcelList(strDate,"LJ_M008") ;
		//ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M008.getIndex(), stratRow, list);

	}

	@Test
	public void test() throws ParseException {
		String strDate = "2021-11-16" ;

		List<List<Object>> list = null ;

		list = excelBeanService.getExcelList(strDate,"LJ_M001") ;

		System.out.println(list);
	}

	@Test
	public void creatHead() throws IOException, ParseException {
		//String toDay = new SimpleDateFormat("yyyyMMdd").format(new Date());

		int stratRow = 3;

		String strDate = "2021-11-10" ;

		String fileDateTime = strDate.replace("-","") ;

		String outPath = "D:\\Idea_Projects\\task-reports\\src\\main\\java\\com\\base\\taskreports\\common\\exel\\report.xlsx";
		String newPath = "D:\\Idea_Projects\\task-reports\\src\\main\\java\\com\\base\\taskreports\\common\\exel\\" + fileDateTime + "_report.xlsx";

		FileUtils.deleteFile(newPath);
		FileUtils.copyFileUsingJava7Files(new File(outPath), new File(newPath));

		ExcelUtils.addHeaderDate(newPath,strDate); // 为所有 Sheet 表头加入日期

		List<List<Object>> list = null ;

		list = excelBeanService.getExcelList(strDate,"LJ_M001") ;

		System.out.println(list);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M001.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M002") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M002.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M003") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M003.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M004") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M004.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M005") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M005.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M006") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M006.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M007") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M007.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M008") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M008.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M009") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M009.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M010") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M010.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M011") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M011.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M012") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M012.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M013") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M013.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M014") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M014.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQL_M001") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQL_M001.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQL_M002") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQL_M002.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M001") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M001.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M002") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M002.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M003") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M003.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M004") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M004.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M005") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M005.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M006") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M006.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M007") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M007.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M008") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M008.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M009") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M009.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M010") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M010.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M011") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M011.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M012") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M012.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M013") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M013.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M014") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M014.getIndex(), stratRow, list);

		//
		list = ljService.getLJ_M001_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M001.getIndex(), 10, list);

		list = ljService.getLJ_M006_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M006.getIndex(), 10, list);

		list = ljService.getLJ_M007_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M007.getIndex(), 10, list);

		list = ljService.getLJ_M008_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M008.getIndex(), 10, list);

		list = ljService.getLJ_M009_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M009.getIndex(), 10, list);

		list = ljService.getLJ_M010_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M010.getIndex(), 10, list);

		list = ljService.getLJ_M011_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M011.getIndex(), 10, list);

		list = ljService.getLJ_M012_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M012.getIndex(), 10, list);

		list = pqdService.getPQD_M001_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M001.getIndex(), 10, list);

		list = pqdService.getPQD_M006_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M006.getIndex(), 10, list);

		list = pqdService.getPQD_M007_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M007.getIndex(), 10, list);

		list = pqdService.getPQD_M008_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M008.getIndex(), 10, list);

		list = pqdService.getPQD_M009_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M009.getIndex(), 10, list);

		list = pqdService.getPQD_M010_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M010.getIndex(), 10, list);

		list = pqdService.getPQD_M011_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M011.getIndex(), 10, list);

		list = pqdService.getPQD_M012_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M012.getIndex(), 10, list);
	}

	@Test
	public void getIndicators() throws ParseException, IOException {

		String toDay = new SimpleDateFormat("yyyyMMdd").format(new Date());

		String outPath = "D:\\Idea_Projects\\task-reports\\src\\main\\java\\com\\base\\taskreports\\common\\exel\\报表展示模板.xlsx";
		String newPath = "D:\\Idea_Projects\\task-reports\\src\\main\\java\\com\\base\\taskreports\\common\\exel\\" + toDay + "_报表展示.xlsx";

		int stratRow = 3;

		FileUtils.deleteFile(newPath);
		FileUtils.copyFileUsingJava7Files(new File(outPath), new File(newPath));

		ExcelUtils.addHeaderDate(newPath); // 为所有 Sheet 表头加入日期

		String strDate = "2021-11-16" ;
		String indicatorCode = "PQL_M001" ;

		/*
		List<List<Object>> list = excelBeanService.getExcelList(strDate,indicatorCode) ;
		System.out.println(list);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.valueOf(indicatorCode).getIndex(), stratRow, list) ;

		for (Indicator indicator : Indicator.values()) {

			System.out.print(indicator.toString()+"-----");

			List<List<Object>> list = excelBeanService.getExcelList(strDate,indicator.toString()) ;
			System.out.println(list);
			if(list != null){
				ExcelUtils.addExcelSheetContent(newPath, indicator.getIndex(), stratRow, list) ;
			}
		}*/

		/*List<List<Object>> list = tblDiscountTransService.getPQD_M001_Detail("2021-11-10") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.valueOf("PQD_M001").getIndex(), 10, list) ;

		list = tblDiscountTransService.getPQD_M006_Detail("2021-11-10") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.valueOf("PQD_M006").getIndex(), 10, list) ;

		list = tblDiscountTransService.getPQD_M007_Detail("2021-11-10") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.valueOf("PQD_M007").getIndex(), 10, list) ;

		list = tblDiscountTransService.getPQD_M008_Detail("2021-11-10") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.valueOf("PQD_M008").getIndex(), 10, list) ;

		list = tblDiscountTransService.getPQD_M009_Detail("2021-11-10") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.valueOf("PQD_M009").getIndex(), 10, list) ;

		list = tblDiscountTransService.getPQD_M010_Detail("2021-11-10") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.valueOf("PQD_M010").getIndex(), 10, list) ;

		list = tblDiscountTransService.getPQD_M011_Detail("2021-11-10") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.valueOf("PQD_M011").getIndex(), 10, list) ;

		list = tblDiscountTransService.getPQD_M012_Detail("2021-11-10") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.valueOf("PQD_M012").getIndex(), 10, list) ;*/

		List<List<Object>> list = null ;

		list = excelBeanService.getExcelList(strDate,"LJ_M001") ;

		System.out.println(list);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M001.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M002") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M002.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M003") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M003.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M004") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M004.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M005") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M005.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M006") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M006.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M007") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M007.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M008") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M008.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M009") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M009.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M010") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M010.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M011") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M011.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M012") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M012.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M013") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M013.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"LJ_M014") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M014.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQL_M001") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQL_M001.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQL_M002") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQL_M002.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M001") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M001.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M002") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M002.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M003") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M003.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M004") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M004.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M005") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M005.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M006") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M006.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M007") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M007.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M008") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M008.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M009") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M009.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M010") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M010.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M011") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M011.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M012") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M012.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M013") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M013.getIndex(), stratRow, list);

		list = excelBeanService.getExcelList(strDate,"PQD_M014") ;
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M014.getIndex(), stratRow, list);

		//
		list = ljService.getLJ_M001_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M001.getIndex(), 10, list);

		list = ljService.getLJ_M006_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M006.getIndex(), 10, list);

		list = ljService.getLJ_M007_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M007.getIndex(), 10, list);

		list = ljService.getLJ_M008_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M008.getIndex(), 10, list);

		list = ljService.getLJ_M009_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M009.getIndex(), 10, list);

		list = ljService.getLJ_M010_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M010.getIndex(), 10, list);

		list = ljService.getLJ_M011_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M011.getIndex(), 10, list);

		list = ljService.getLJ_M012_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.LJ_M012.getIndex(), 10, list);

		list = pqdService.getPQD_M001_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M001.getIndex(), 10, list);

		list = pqdService.getPQD_M006_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M006.getIndex(), 10, list);

		list = pqdService.getPQD_M007_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M007.getIndex(), 10, list);

		list = pqdService.getPQD_M008_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M008.getIndex(), 10, list);

		list = pqdService.getPQD_M009_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M009.getIndex(), 10, list);

		list = pqdService.getPQD_M010_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M010.getIndex(), 10, list);

		list = pqdService.getPQD_M011_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M011.getIndex(), 10, list);

		list = pqdService.getPQD_M012_Detail(strDate);
		ExcelUtils.addExcelSheetContent(newPath, Indicator.PQD_M012.getIndex(), 10, list);

	}

}
